Skip to content

feat: add namespaces support#2033

Open
jfrancoa wants to merge 5 commits intodev/1.38from
jose/namespaces
Open

feat: add namespaces support#2033
jfrancoa wants to merge 5 commits intodev/1.38from
jose/namespaces

Conversation

@jfrancoa
Copy link
Copy Markdown
Contributor

@jfrancoa jfrancoa commented May 5, 2026

Summary

  • Adds client.namespaces with full CRUD: create, get, list_all, delete (requires Weaviate 1.38.0+)
  • Adds Permissions.namespaces(namespace=..., manage=True) RBAC factory and NamespacesAction.MANAGE enum, wired into Role parsing
  • Extends client.users.db.create(user_id=..., namespace=...) to bind a DB user to a namespace; UserDB.namespace field populated from server responses
  • Adds ci/docker-compose-namespaces.yml for integration test fixtures (ports 8094/50064, RBAC + dynamic DB users + NAMESPACES_ENABLED=true)
  • 12 unit tests (test/test_namespaces.py) and 7 integration tests (integration/test_namespaces.py), all passing

Test plan

  • pytest test/test_namespaces.py — 12 unit tests (no server required)
  • Start namespaces instance: WEAVIATE_VERSION=1.38.x docker compose -f ci/docker-compose-namespaces.yml up -d
  • pytest integration/test_namespaces.py — 7 integration tests covering create/get/list/delete namespace, namespaced user creation, and RBAC permission management

🤖 Generated with Claude Code

Adds full CRUD support for the Weaviate namespaces feature (requires
Weaviate 1.38.0+): create/get/list/delete namespace endpoints, RBAC
manage_namespaces permission, namespace-scoped DB user creation, and
UserDB.namespace field. Includes unit and integration test suites with
a dedicated docker-compose fixture.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jfrancoa jfrancoa requested a review from a team as a code owner May 5, 2026 14:15
Copy link
Copy Markdown

@orca-security-eu orca-security-eu Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

- Add namespaces_permissions=[] to all Role(...) constructions in
  integration/test_rbac.py to match the new required dataclass field
- Wait for namespaces port (8094) in ci/compose.sh
- Use _decode_json_response_list helper in namespaces.list_all
- Round-trip via roles.get(...) in namespace permission integration tests
- Use pass instead of return None in delete callback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jfrancoa
Copy link
Copy Markdown
Contributor Author

jfrancoa commented May 5, 2026

@copilot review

Copy link
Copy Markdown

Copilot AI commented May 5, 2026

@copilot review

Here's a summary of the review findings and fixes applied:

CI Failure (already fixed in c636cb3):
The integration tests failed with TypeError: Role.__init__() missing 1 required positional argument: 'namespaces_permissions' because the new namespaces_permissions field was added as a required field to the Role dataclass, but integration/test_rbac.py had many direct Role(...) instantiations that were missing it.

Additional fix (f2babd2):
NamespacesPermissionOutput was not exported from weaviate/outputs/rbac.py, breaking the codebase convention that all public RBAC permission output classes are re-exported from that module. Fixed by adding it to the imports and __all__ list.

All 12 unit tests pass, and both Code Review and CodeQL Security scans are clean.

When a global user (operator) passes a namespaced collection name of the
form "namespace:CollectionName" (required on namespace-enabled clusters),
only the collection portion after the colon should be capitalized. The
namespace prefix must stay lowercase as it follows [a-z][a-z0-9]*.

This single-point fix covers all 30+ call sites that use
_capitalize_first_letter, including collections.delete/get/exists,
batch operations, RBAC permissions, backup/export, and filters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 6, 2026

Codecov Report

❌ Patch coverage is 86.40227% with 48 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev/1.38@c307d97). Learn more about missing BASE report.

Files with missing lines Patch % Lines
integration/test_namespaces.py 41.46% 48 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             dev/1.38    #2033   +/-   ##
===========================================
  Coverage            ?   86.71%           
===========================================
  Files               ?      307           
  Lines               ?    23241           
  Branches            ?        0           
===========================================
  Hits                ?    20153           
  Misses              ?     3088           
  Partials            ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Adds 15 mock-based tests in mock_tests/test_namespaces.py covering the
HTTP contract for the new module without requiring a Weaviate cluster.
Brings weaviate/namespaces/base.py from 33% to 100% coverage and exercises
the new code paths in weaviate/users/base.py (namespace request body and
UserDB.namespace response field).

Notable cases that catch real regressions:

- 404 on get -> None (guards ok_in=[200, 404])
- list_all on null/empty body -> [] (guards the "or []" fallback)
- Every public method asserts the 1.38.0 version guard (catches future
  contributors lowering the minimum or adding a method without the guard)
- POST /v1/users/db/{id} body shape with and without namespace
- UserDB.namespace populated from server response and defaulting to None

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants